Enviado por: Troncof
Fecha: 2003-06-28 04:43:24
Actualizado: 2003-06-28 08:49:05
¿Usa base de datos?: 0
Visitas: 3752
Votos: 5
Descargado: 1565 veces
Valoración: 3.20
» Valora este script «
ZipDescargar

Este script lo he conseguido de http://usuarios.lycos.es/codigohtm/php/ y la direccion de correo del creador es [email protected] para cualquier duda. Este script consta de 3 archivos .php y no necesita la base datos: [b]index.php[/b] (Indice) [codigo]<? include("config.php"); //incluimos el fichero config.php donde tenemos la configuraci�n del script if(!file_exists($file)) //si el txt no existe... { $fp=fopen($file,"w"); //creamos un txt por si no t� creado fputs($fp,"0n0n0n0"); //le ponemos las respuestas desde 0 fclose($fp); //cerramos el txt } ?> <form method=POST action="enc_ver.php"> <input type="radio" name="En" value="E1" checked><? echo $c1;?><br> <input type="radio" name="En" value="E2"><? echo $c2;?><br> <input type="radio" name="En" value="E3"><? echo $c3;?><br> <input type="radio" name="En" value="E4"><? echo $c4;?><br> <input type="submit" value="OK" name="Bot"> </form> <p>[/codigo] [b]config.php[/b](para configurar la encuesta) [codigo]<? // CONFIGURACION DE LA ENCUESTA $file="base.txt"; //nombre del txt en el que guardaremos los resultados //Escribe tus respuestas para la encuesta $c1="N� 1"; //Encuesta n� 1 $c2="N� 2"; //Encuesta n� 2 $c3="N� 3"; //Encuesta n� 3 $c4="N� 4"; //Encuesta n� 4 ?>[/codigo] [b]enc_ver.php[/b] (Resultados) [codigo] <? include("config.php"); //incluimos el fichero config.php donde tenemos la configuraci�n del script $file2=file($file); //creamos el array con las lineas del archivo $lineas=count($file2);//contamos los elementos del array, es decir el total de lineas $n1=$file2[0]; //asignamos a la variable el n� de votos(la l�nea 1 del txt) $n2=$file2[1]; //asignamos a la variable el n� de votos(la l�nea 2 del txt) $n3=$file2[2]; //asignamos a la variable el n� de votos(la l�nea 3 del txt) $n4=$file2[3]; //asignamos a la variable el n� de votos(la l�nea 4 del txt) if($En=="E1") //si la respuesta es la opci�n 1... {$nn1=intval($n1)+1;}else{$nn1=intval($n1);} //entonces sumamos uno a $nn1, si no, se keda igual if($En=="E2") //si la respuesta es la opci�n ... {$nn2=intval($n2)+1;}else{$nn2=intval($n2);} //entonces sumamos uno a $nn2, si no, se keda igual if($En=="E3") //si la respuesta es la opci�n 3... {$nn3=intval($n3)+1;}else{$nn3=intval($n3);} //entonces sumamos uno a $nn3, si no, se keda igual if($En=="E4") //si la respuesta es la opci�n 4... {$nn4=intval($n4)+1;}else{$nn4=intval($n4);} //entonces sumamos uno a $nn4, si no, se keda igual $fp=fopen($file,"w+"); //abrimos de nuevo el txt borr�ndolo todo fwrite($fp,"$nn1n$nn2n$nn3n$nn4"); //escribimos en el txt los votos.. en su respectiva l�nea. NOTA: n <- cambia de l�nea ;) fclose($fp); //cerramos el txt $ntotal=$nn1+$nn2+$nn3+$nn4; //contamos el n� total de votos ?> <table border=0 cellpadding=0 cellspacing=0 width=188> <tr> <td colspan=3 width=186><strong><font face=Arial>Resultados Encuesta</font></strong></td> </tr> <tr> <td width=46><font face=Arial><? echo $c1;?></font></td> <td width=101><table border=0 cellpadding=0 cellspacing=1 width=100 bgcolor="#000080"> <tr> <td><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn1*100/$ntotal;?> bgcolor=#FFFFFF height=5> <tr> <td></td> </tr> </table> </td> </tr> </table> </td> <td width=37><p align=center><font face=Arial size=2><? echo $nn1;?></font></td> </tr> <tr> <td width=46><font face=Arial><? echo $c2;?></font></td> <td width=101><table border=0 cellpadding=0 cellspacing=1 width=100% bgcolor=#000080> <tr> <td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn2*100/$ntotal;?> bgcolor=#FFFFFF height=5> <tr> <td></td> </tr> </table> </td> </tr> </table> </td> <td width=37><p align=center><font face=Arial size=2><? echo $nn2;?></font></td> </tr> <tr> <td width=46><font face=Arial><? echo $c3;?></font></td> <td width=101><table border=0 cellpadding=0 cellspacing=1 width=100% bgcolor=#000080> <tr> <td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn3*100/$ntotal;?> bgcolor=#FFFFFF height=5> <tr> <td></td> </tr> </table> </td> </tr> </table> </td> <td width=37><p align=center><font face=Arial size=2><? echo $nn3;?></font></td> </tr> <tr> <td width=46><font face=Arial><? echo $c4;?></font></td> <td width=101><table border=0 cellpadding=0 cellspacing=1 width=100% bgcolor=#000080> <tr> <td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn4*100/$ntotal;?> bgcolor=#FFFFFF height=5> <tr> <td></td> </tr> </table> </td> </tr> </table> </td> <td width=37><p align=center><font face=Arial size=2><? echo $nn4;?></font></td> </tr> <tr> <td width=184 colspan=3><font face=Arial>Total encuesta: </font><font color=#004080 face=Arial size=2><strong><? echo $ntotal;?></strong></font></td> </tr> </table> <br> <a href="index.php">Volver</a>[/codigo] Creo que no me he equivocado en nada. Este es mi primer script que mando y a lo mejor algo est� mal copiado. El script crea un archivo base.txt para almacenar los votos.